<?php
	session_start();
$nPageNumber=25;
	include("mysql_connect.php");
	
	$strKeyWord = $_POST['strLocation'];
	$isSale = $_POST['isSale'];
	
	$strSqlCommand = 'SELECT COUNT(*) 
						FROM ResidentialProperty tbRP
						LEFT JOIN Listing tbLT			ON tbRP.Listing_idListing = tbLT.idListing
						LEFT JOIN StreetAddress tbSA	ON tbLT.StreetAddress_idStreetAddress = tbSA.idStreetAddress
						LEFT JOIN ListingData tbLD		ON tbLT.ListingData_idListingData = tbLD.idListingData
						LEFT JOIN Baths tbBT			ON tbBt.idBaths = tbRp.Baths_idBaths
						LEFT JOIN Rooms tbRM			ON tbRm.idRooms = tbRp.Rooms_idRooms
					  	WHERE ( PostalCode = "'. $strKeyWord.'" OR City LIKE "%'.$strKeyWord.'%")';
	//					LEFT JOIN CurrencyFormat tbPR	ON tbLD.Price = tbPR.idCurrencyFormat
	if( $isSale == "true" )$strSqlCommand .= ' AND Category_idCategory != 5';
	else $strSqlCommand .= ' AND Category_idCategory = 5';
	$result = mysql_query($strSqlCommand);
	
	//echo $strSqlCommand."<br/>";
	$rowCount = @mysql_fetch_row($result);
	
	$_SESSION['StrItem'] = 0;
	$_SESSION['MaxItem'] = $rowCount[0] - $nPageNumber;
	
	$_SESSION['SearchKey'] = 'SELECT idResidentialProperty, idListing, Price, Bedrooms, BathTotal, StreetNumber, StreetDirPrefix, StreetName, UnitNumber, City, StateOrProvince, PostalCode, URL, Latitude, Longitude
								FROM ResidentialProperty tbRP
								LEFT JOIN Listing  tbLT			ON tbRP.Listing_idListing = tbLT.idListing
								LEFT JOIN StreetAddress  tbSA	ON tbLT.StreetAddress_idStreetAddress = tbSA.idStreetAddress
								LEFT JOIN ListingData  tbLD		ON tbLT.ListingData_idListingData = tbLD.idListingData
								LEFT JOIN Baths  tbBT			ON tbBt.idBaths = tbRp.Baths_idBaths
								LEFT JOIN GeographicData tbGEO  ON tbSA.idStreetAddress = tbGEO.idGeographicData
								LEFT JOIN PictureData tbPD		ON tbLT.PictureData_idPictureData  = tbPD.idPictureData			
							  	WHERE ( PostalCode = "'. $strKeyWord.'" OR City LIKE "%'.$strKeyWord.'%")';
//								LEFT JOIN CurrencyFormat  tbPR	ON tbLD.Price = tbPR.idCurrencyFormat
//LEFT JOIN Rooms  tbRM			ON tbRm.idRooms = tbRp.Rooms_idRooms
	if( $isSale == "true"  )
	{
		$_SESSION['SearchKey'] .= ' AND Category_idCategory != 5';
//		$_SESSION['ImagePath'] = 'images/Residential_Photo/Photo';
	}
	else
	{ 
		$_SESSION['SearchKey'] .= ' AND Category_idCategory = 5';
//		$_SESSION['ImagePath'] = 'images/Rental_Photo/-';
	}
//						LIMIT ".$_SESSION['StrItem'].", 6";
	
	$result = mysql_query($_SESSION['SearchKey'] ." LIMIT ".$_SESSION['StrItem'].", ".$nPageNumber);
	
	$_SESSION["MapAddress"] = 'https://maps.googleapis.com/maps/api/staticmap?center=';
	$nIdx = 0;
	include_once("OutputPropertyList.php");
	while($rowDetail = @mysql_fetch_array($result))	
	{// URL, Price,idListing
		PrintProperty( $rowDetail, $nIdx);
		$nIdx++;
/*	
				echo '<a class="ViewDetailBlock" id="'.$rowDetail['idResidentialProperty'].'" href="#page14" style="text-decoration: none; color: #000000;">';
		echo '<div class="ui-grid-a ">';
			echo '<div class="ui-block-a property-image" style="position: relative">';
 				echo '<div class="property-image-canvas" style="position: absolute;">';
					echo '<img src="'.$_SESSION['Host'].$_SESSION['ImagePath'].$rowDetail['idListing'].'-1.jpeg" HSPACE="0"/>';
				echo '</div>';
//				echo '<div style="background-image: url('.$_SESSION['Host'].$_SESSION['ImagePath'].$rowDetail['idListing'].'-1.jpeg); width: 100px; height: 75px; position: absolute;">';
				//echo '<img src="'.$_SESSION['Host'].$_SESSION['ImagePath'].$rowDetail['idListing'].'-1.jpeg"/>';
           			echo '<div class="property-image-text" style="position: absolute;">';
	        			echo '<font size="2" style="background-color:#00ff00;">$'.$rowDetail['Currency'].'</font>';
					echo '</div>';
//					echo '<img src="'.$_SESSION['Host'].$_SESSION['ImagePath'].$rowDetail['idListing'].'-1.jpeg" class="property-image-src"/>';
//				ImageWithPrice( $_SESSION['Host'].$_SESSION['ImagePath'].$rowDetail['idListing'].'-1.jpeg', $rowDetail['Currency']);
//				echo '</div>';
			echo '</div>';
		
		$strAddress = $rowDetail['StreetNumber']. '+'.$rowDetail['StreetName'] . '+' . $rowDetail['City'];// . '+' . $rowDetail['StateOrProvince'];
		if($nIdx == 0)
		{
			$_SESSION["MapAddress"] .= $strAddress . "&zoom=11&size=288x400";
		}
		$nIdx++;
		$_SESSION["MapAddress"] .= "&markers=label:".$nIdx."%7C".$strAddress;		
//		$strSqlCommand = "SELECT ThePrice FROM Price
//						  WHERE idPrice = ".$rowDetial[1];		
//		$resultPrice = mysql_query($strSqlCommand);
//		$rowPrice = @mysql_fetch_row($resultPrice);

			echo '<div class="ui-block-b property-description">';
				echo '<div>';
//					echo "<p>".$rowDetail['StreetNumber']." ".$rowDetail['StreetName']." ".$rowDetail['UnitNumber']."</p>";
//					echo "<p>".$rowDetail['City'].", ".$rowDetail['StateOrProvince'].", ".$rowDetail['PostalCode']."</p>";
					echo "<p>".$rowDetail['StreetNumber']." ".$rowDetail['StreetName']."</p>";
					echo "<p>".$rowDetail['City'].", ".$rowDetail['PostalCode']."</p>";
					//echo "<p>".$rowType[0]." Bedrooms, ".$rowType[1]." Bathrooms</p>";
					echo "<p>".$rowDetail['TotalRooms']." Bedrooms, ".$rowDetail['BathTotal']." Bathrooms</p>";
//					echo "<p>".$rowDetail['Currency']."</p>";
//				echo "</div>";
//				echo '<div>';
					include_once( "getLatLong.php" );
					$geoLatLon = getLatLong( $rowDetail['StreetNumber']." ".$rowDetail['StreetName']." ".$rowDetail['UnitNumber'].
										" ".$rowDetail['City']." ".$rowDetail['StateOrProvince']." ".$rowDetail['PostalCode'] );
					$lat = $geoLatLon['lat'];
					$long = $geoLatLon['long'];
				
//					include("http://www.bespoke-app.com/Realty/WorkScoreAPI.php?lat=$lat&lon=$long");
					echo "Walk Score: ".rand(80,95);
				
//					getWalkScore( $geoLatLon['lat'], $geoLatLon['long'], 
//										$rowDetail['StreetNumber']." ".$rowDetail['StreetName']." ".$rowDetail['UnitNumber'].
//										" ".$rowDetail['City']." ".$rowDetail['StateOrProvince']." ".$rowDetail['PostalCode'] );
					//echo $json;
					
				echo "</div>";
				
		//$_SESSION["PropertyId"] = $rowType[2];
//		$_SESSION["PropertyId"] = $rowDetial[4];
//			$strAddress = $rowAddress[1]. ' '.$rowAddress[3] . ' ' . $rowAddress[5] . ' ' . $rowAddress[6];
//		$_SESSION["MapAddress"] = str_replace( " ","+", $strAddress);
			//echo '<input type="hidden" id="Property" value="'.$rowType[2].'">';
			//echo '<input type="hidden" class="Property" value="'.$rowDetial[4].'">';
			echo '</div>';
		echo '</div>';//class="ui-grid-a"
				echo '</a>';
			
/*	
		echo '<div class="ui-grid">';
			echo '<a data-role="button" data-transition="slide" href="#page14" class="ui-btn ui-shadow ui-btn-corner-all ui-btn-up-c PropertyDetail">';
			// data-corners="true" data-shadow="true"
			//data-iconshadow="true" data-iconsize="18" data-wrapperels="span" data-theme="c" 
			//
			echo '<input type="hidden" value="'.$rowDetial[4].'" class="Property"/>';
			echo '<span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">';
			echo "View Details";
			echo '</span></span>';
			echo '</a>';
		
		echo '</div>';
*/	//echo '</div>';//<!-- /grid-a -->";//<div><p></p></div>';
		//

	}
	$_SESSION["MapAddress"] .= "&sensor=false";
	
?>